/*
 * @Date: 2025-06-13 10:50:10
 * @Auth: 463997479@qq.com
 * @LastEditors: 463997479@qq.com
 * @LastEditTime: 2025-08-29 15:55:32
 * @FilePath: \corpus\src\pages\Home\PermisionMenu\index.tsx
 */
import { Checkbox, Col, Form, Modal, Row } from 'antd';
import type React from 'react';
import { useEffect } from 'react';
import hooks from '../hooks/useHooks';

const AddDeptUser: React.FC<{ account: number; check: number[] }> = (props: {
  account: number;
  check: number[];
}) => {
  const title = '部门权限修改';

  const { getData, data, updateDept, permisionVisible, setPermisionVisible } = hooks.useContainer();

  const [form] = Form.useForm();
  useEffect(() => {
    getData.run({ current: 1, pageSize: 100, type: 'bm' });
  }, []);
  const handleSubmit = () => {
    form.validateFields().then(async (vals) => {
      console.log(vals);
      const method = updateDept;
      method.run({
        ...vals,
        account: props.account,
      });
    });
  };
  useEffect(() => {
    console.log(props);
    if (permisionVisible) {
      form.setFieldValue('knowledges', props.check ?? []);
    }
  }, [props.check, permisionVisible]);
  return (
    <Modal
      width={700}
      title={title}
      open={permisionVisible}
      onCancel={() => {
        setPermisionVisible(false);
        form.resetFields();
      }}
      onOk={handleSubmit}
    >
      <div style={{ padding: '10.0px' }}>
        <Form labelCol={{ span: 4 }} style={{ marginBottom: '20.0px' }} form={form}>
          <Form.Item
            label="知识库"
            name="knowledges"
            rules={[{ required: true, message: '请选择' }]}
          >
            <Checkbox.Group>
              <Row>
                {data?.data?.map((item: { name: string; id: number }) => (
                  <Col key={item.id} span={12}>
                    <Checkbox value={item.id} style={{ lineHeight: '32px' }}>
                      {item.name}
                    </Checkbox>
                  </Col>
                ))}
              </Row>
            </Checkbox.Group>
          </Form.Item>
        </Form>
      </div>
    </Modal>
  );
};

export default AddDeptUser;
